package com.fm.common.net.baseCoroutine.exception

import com.ticket.rccl.net.baseCoroutine.listener.CoroutineErrorListener
import kotlinx.coroutines.CoroutineExceptionHandler
import kotlin.coroutines.AbstractCoroutineContextElement
import kotlin.coroutines.CoroutineContext

/**
 * @CreateData:     2020/12/22
 * @Author:         lyy
 * @Description:    类描述
 */

class UncaughtCoroutineExceptionHandler(private val errorHandler: CoroutineErrorListener?=null)  :
    CoroutineExceptionHandler, AbstractCoroutineContextElement(CoroutineExceptionHandler.Key) {

    override fun handleException(context: CoroutineContext, exception: Throwable) {
        exception.printStackTrace()

        errorHandler?.onError(exception)
    }
}